﻿using System;
using System.Drawing;
using System.Windows.Forms;
using System.Text;
using System.Security.Cryptography;
using System.Collections.Generic;
using System.Data;
using System.Reflection;

namespace QL_Truong_Hoc
{
    internal static class clsCommon
    {
        private const string mcstrClassName = "frmDanhSachDuTuyen";         //class name

        /// <summary>
        /// Show Error Message
        /// </summary>
        /// <param name="strModule">Method/function name</param>
        /// <param name="strMsg">Custom message to show</param>
        /// <returns></returns>
        public static bool fncMsgError(string strClass, string strModule, string strMsg)
        {
            bool blnResult = false;

            try
            {
                string strMsgShow = string.Format("Class : {0} \nMethod : {1} \nMessage : \n{2}", strClass, strModule, strMsg);

                //MessageBox.Show(strMsgShow, clsConst.gcstrAppName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                DevExpress.XtraEditors.XtraMessageBox.Show(strMsgShow, clsConst.gcstrAppName, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return true;
            }
            catch (Exception ex) { DevExpress.XtraEditors.XtraMessageBox.Show(ex.StackTrace, clsConst.gcstrAppName, MessageBoxButtons.OK, MessageBoxIcon.Error); }

            return blnResult;
        }

        /// <summary>
        /// Show ERROR message
        /// </summary>
        /// <param name="strMsg"></param>
        /// <returns></returns>
        public static bool fncMsgError(string strMsg)
        {
            bool blnResult = false;

            try
            {
                //MessageBox.Show(strMsg, clsConst.gcstrAppName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                DevExpress.XtraEditors.XtraMessageBox.Show(strMsg, clsConst.gcstrAppName, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return true;
            }
            catch (Exception ex) { DevExpress.XtraEditors.XtraMessageBox.Show(ex.StackTrace, clsConst.gcstrAppName, MessageBoxButtons.OK, MessageBoxIcon.Error); }

            return blnResult;
        }

        /// <summary>
        /// Show information message
        /// </summary>
        /// <param name="strMsg"></param>
        /// <returns></returns>
        public static bool fncMsgInfo(string strMsg)
        {
            bool blnResult = false;

            try
            {
                //MessageBox.Show(strMsg, clsConst.gcstrAppName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                DevExpress.XtraEditors.XtraMessageBox.Show(strMsg, clsConst.gcstrAppName, MessageBoxButtons.OK, MessageBoxIcon.Information);

                return true;
            }
            catch (Exception ex) { DevExpress.XtraEditors.XtraMessageBox.Show(ex.StackTrace, clsConst.gcstrAppName, MessageBoxButtons.OK, MessageBoxIcon.Error); }

            return blnResult;
        }

        /// <summary>
        /// Show warning message
        /// </summary>
        /// <param name="strMsg"></param>
        /// <returns></returns>
        public static bool fncMsgWarning(string strMsg)
        {
            bool blnResult = false;

            try
            {
                //MessageBox.Show(strMsg, clsConst.gcstrAppName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                DevExpress.XtraEditors.XtraMessageBox.Show(strMsg, clsConst.gcstrAppName, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                return true;
            }
            catch (Exception ex) { DevExpress.XtraEditors.XtraMessageBox.Show(ex.StackTrace, clsConst.gcstrAppName, MessageBoxButtons.OK, MessageBoxIcon.Error); }

            return blnResult;
        }

        /// <summary>
        /// Show confirm message
        /// </summary>
        /// <param name="strMsg"></param>
        /// <returns></returns>
        public static bool fncMsgConfirm(string strMsg)
        {
            bool blnResult = false;

            try
            {
                //if (MessageBox.Show(strMsg, clsConst.gcstrAppName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) return true;
                if (DevExpress.XtraEditors.XtraMessageBox.Show(strMsg, clsConst.gcstrAppName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) return true;

                return false;
            }
            catch (Exception ex) { DevExpress.XtraEditors.XtraMessageBox.Show(ex.StackTrace, clsConst.gcstrAppName, MessageBoxButtons.OK, MessageBoxIcon.Error); }

            return blnResult;
        }

        /// <summary>
        /// Show open file dialog
        /// </summary>
        /// <param name="strFilter"></param>
        /// <returns></returns>
        public static string fncOpenFile(string strFilter)
        {
            string strResult = "";
            try
            {
                using (OpenFileDialog objOpen = new OpenFileDialog())
                {
                    objOpen.Filter = strFilter;
                    if (objOpen.ShowDialog() == DialogResult.OK) strResult = objOpen.FileName;
                }
            }
            catch (Exception ex) { DevExpress.XtraEditors.XtraMessageBox.Show(ex.StackTrace, clsConst.gcstrAppName, MessageBoxButtons.OK, MessageBoxIcon.Error); }
            return strResult;
        }

        /// <summary>
        /// Kiem tra chuoi la null
        /// Author: QuyetLT
        /// </summary>
        /// <param name="strText">Chuoi dau vao</param>
        /// <param name="strMsg">Message thong bao</param>
        /// <returns>Bool</returns>
        public static bool fncIsBlank(string strText, string strMsg = null)
        {
            bool blnResult = false;
            try
            {
                if (DBNull.Value.Equals(strText)) return true;

                if (string.IsNullOrEmpty(strText))
                {
                    //show message and set focus if available
                    if (strMsg != null) fncMsgWarning(strMsg);
                    blnResult = true;
                }
            }
            catch (Exception ex) { throw ex; }
            return blnResult;
        }

        /// <summary>
        /// Convert gia tri sang DbDatetime
        /// </summary>
        /// <param name="dtValue"></param>
        /// <returns></returns>
        public static object fncCnvToDbDatetime(DateTime dtValue)
        {
            if (dtValue <= DateTime.MinValue || dtValue >= DateTime.MaxValue) return System.Data.SqlTypes.SqlDateTime.Null;
            return dtValue;
        }

        /// <summary>
        /// Convert gia tri sang DbString
        /// </summary>
        /// <param name="strInput"></param>
        /// <returns></returns>
        public static object fncCnvToDbString(string strInput)
        {
            if (DBNull.Value.Equals(strInput)) return "";
            if (string.IsNullOrEmpty(strInput)) return "";

            strInput = strInput.Replace("[", "[[]");
            //strInput = "'" + strInput.Replace("'", "''") + "'";
            strInput = strInput.Replace("'", "''");

            return strInput;
        }

        /// <summary>
        /// Convert gia tri sang Dbbit
        /// Author: QuyetLT
        /// </summary>
        /// <param name="blnInput">Gia tri vao</param>
        /// <returns>1 hoac 0</returns>
        public static object fncCnvToDbBit(bool blnInput)
        {
            if (blnInput) return 1;
            return 0;
        }

        /// <summary>
        /// Convert gia tri sang DbImage
        /// </summary>
        /// <param name="objImage"></param>
        /// <returns></returns>
        public static object fncCnvToDbImage(Image objImage)
        {
            if (objImage == null) return "";
            return objImage;
        }

        /// <summary>
        /// Chuyen doi sang string
        /// </summary>
        /// <param name="objInput"></param>
        /// <returns>string</returns>
        public static string fncCnvNullToString(object objInput)
        {
            string strResult = "";

            try
            {
                //tra ve "" neu input la null
                if (Convert.IsDBNull(objInput)) return "";
                if (objInput == null) return "";
                strResult = Convert.ToString(objInput);
            }
            catch (Exception ex) { return ""; }

            return strResult;
        }

        /// <summary>
        /// Chuyen doi sang byte[]
        /// </summary>
        /// <param name="objInput"></param>
        /// <returns>byte[]</returns>
        public static byte[] fncCnvNullToByteArray(object objInput)
        {
            byte[] strResult = null;

            try
            {
                //tra ve "" neu input la null
                if (Convert.IsDBNull(objInput)) return strResult;
                if (objInput == null) return strResult;
                strResult = (byte[])(objInput);
            }
            catch (Exception ex) { return strResult; }

            return strResult;
        }

        /// <summary>
        /// Chuyen doi sang int
        /// </summary>
        /// <param name="objInput"></param>
        /// <returns>int</returns>
        public static int fncCnvNullToInt(object objInput)
        {
            string strTemp = fncCnvNullToString(objInput);
            int intResult = 0;
            int.TryParse(strTemp, out intResult);
            return intResult;
        }

        /// <summary>
        /// Chuyen doi sang float
        /// </summary>
        /// <param name="objInput"></param>
        /// <returns>float</returns>
        public static float fncCnvNullToFloat(object objInput)
        {
            string strTemp = fncCnvNullToString(objInput);
            float fltResult = 0F;
            float.TryParse(strTemp, out fltResult);
            return fltResult;
        }

        /// <summary>
        /// Chuyen doi sang bool
        /// </summary>
        /// <param name="objInput"></param>
        /// <returns>bool</returns>
        public static bool fncCnvNullToBool(object objInput)
        {
            string strTemp = fncCnvNullToString(objInput).Trim();

            if (strTemp == "1") return true;
            if (strTemp == "0") return false;

            bool blnResult = false;
            bool.TryParse(strTemp, out blnResult);
            return blnResult;
        }

        /// <summary>
        /// Chuyen doi bool sang int
        /// </summary>
        /// <param name="objInput"></param>
        /// <returns>bool</returns>
        public static int fncCnvBoolToInt(object objInput)
        {
            string strTemp = fncCnvNullToString(objInput).Trim().ToLower();

            if (strTemp == "true") return 1;
            if (strTemp == "false") return 0;

            return 0;
        }

        /// <summary>
        /// Chuyen doi sang Datetime
        /// </summary>
        /// <param name="objInput"></param>
        /// <returns>DateTime</returns>
        public static DateTime fncCnvNullToDatetime(object objInput)
        {
            string strTemp = fncCnvNullToString(objInput);
            DateTime dtResult = DateTime.MinValue;
            DateTime.TryParse(strTemp, out dtResult);
            return dtResult;
        }

        /// <summary>
        /// In hoa chữ cái đầu tiên
        /// </summary>
        /// <param name="strValue"></param>
        /// <returns></returns>
        public static string fncCapitalizeFirst(string strValue)
        {
            System.Globalization.TextInfo ti = new System.Globalization.CultureInfo("en-US", false).TextInfo;
            return ti.ToTitleCase(strValue);
        }

        /// <summary>
        /// Trả về HọĐệm + Tên từ họ tên đầy đủ
        /// Author: QuyetLT
        /// </summary>
        /// <param name="strHoten">Tên đầy đủ</param>
        /// <param name="strHoDem">Trả về họ đệm</param>
        /// <param name="strTen">Trả về tên</param>
        /// <returns>bool - true - thành công, false-thất bại</returns>
        public static bool fncGetHoTen(string strHoten, out string strHoDem, out string strTen)
        {
            strHoDem = "";
            strTen = "";

            try
            {
                strHoten = strHoten.Trim();

                int intIndex = strHoten.LastIndexOf(" ");

                if (intIndex <= 0)
                {
                    strHoDem = "";
                    strTen = strHoten;
                }
                else
                {
                    strHoDem = strHoten.Substring(0, intIndex + 1).Trim();
                    strTen = strHoten.Substring(intIndex).Trim();
                }

                return true;
            }
            catch (Exception ex)
            {
                clsCommon.fncMsgError(mcstrClassName, "fncGetData", ex.Message);
                return false;
            }
        }

        /// <summary>
        /// Xây dựng câu query like
        /// Author: QuyetLT
        /// </summary>
        /// <param name="strField">Tên trường</param>
        /// <param name="strQuery">Dữ liệu query</param>
        /// <returns>string</returns>
        public static string fncBuildQueryLike(string strField, string strQuery)
        {
            string strReturnValue = null;

            strReturnValue = "";
            string[] strArr = null;

            try
            {
                //trim and remove double space
                strQuery = strQuery.Trim();
                strQuery = strQuery.Replace("  ", "");

                //split into array
                strArr = strQuery.Split(new char[] { ' ' });

                //start concat

                for (int i = 0; i <= strArr.Length - 2; i++)
                {
                    //build to get string like : FIELDNAME Like '%abc%'
                    strReturnValue += " " + strField;
                    strReturnValue += " LIKE ";
                    strReturnValue += "'";
                    strReturnValue += fncCnvToDbString("%" + strArr[i] + "%");
                    strReturnValue += "'";
                    strReturnValue += " AND";
                }

                //concat with the last item
                strReturnValue += " " + strField;
                strReturnValue += " LIKE ";
                strReturnValue += "'";
                strReturnValue += fncCnvToDbString("%" + strArr[strArr.Length - 1] + "%");
                strReturnValue += "'";
            }
            catch (Exception ex)
            {
                clsCommon.fncMsgError(mcstrClassName, "fncBuildQueryLike", ex.Message);
                return "";
            }
            finally
            {
                strArr = null;
            }
            return strReturnValue;
        }

        /// <summary>
        /// Release COM object
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool fncReleaseObject(object obj)
        {
            bool blnReturnValue = false;

            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;

                return true;
            }
            catch (Exception ex)
            {
                obj = null;
            }
            finally
            {
                GC.Collect();
            }
            return blnReturnValue;
        }

        /// <summary>
        /// Open database
        /// </summary>
        /// <returns></returns>
        public static bool fncOpenConnection()
        {
            bool blnResult = false;
            try
            {
                Program.gobjConn.Open();
            }
            catch { clsCommon.fncMsgError("Không thể kết nối với cơ sở dữ liệu. Xin hãy thử lại."); }
            return blnResult;
        }

        /// <summary>
        /// Close database
        /// </summary>
        /// <returns></returns>
        public static bool fncCloseConnection()
        {
            bool blnResult = false;
            try
            {
                Program.gobjConn.Close();
            }
            catch { clsCommon.fncMsgError("Không thể kết nối với cơ sở dữ liệu. Xin hãy thử lại."); }
            return blnResult;
        }

        /// <summary>
        /// take any string and encrypt it using MD5 then
        /// return the encrypted data 
        /// </summary>
        /// <param name="data">input text you will enterd to encrypt it</param>
        /// <returns>return the encrypted text as hexadecimal string</returns>
        public static string fncGetMD5HashData(string data)
        {
            //create new instance of md5
            MD5 md5 = MD5.Create();

            //convert the input text to array of bytes
            byte[] hashData = md5.ComputeHash(Encoding.Default.GetBytes(data));

            //create new instance of StringBuilder to save hashed data
            StringBuilder returnValue = new StringBuilder();

            //loop for each byte and add it to StringBuilder
            for (int i = 0; i < hashData.Length; i++)
            {
                returnValue.Append(hashData[i].ToString());
            }

            // return hexadecimal string
            return returnValue.ToString();
        }

        /// <summary>
        /// take any string and encrypt it using SHA1 then
        /// return the encrypted data
        /// </summary>
        /// <param name="data">input text you will enterd to encrypt it</param>
        /// <returns>return the encrypted text as hexadecimal string</returns>
        public static string fncGetSHA1HashData(string data)
        {
            try
            {
                //create new instance of sha1
                SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();

                //convert the input text to array of bytes
                byte[] hashData = sha1.ComputeHash(Encoding.Default.GetBytes(data));

                //create new instance of StringBuilder to save hashed data
                StringBuilder returnValue = new StringBuilder();

                //loop for each byte and add it to StringBuilder
                for (int i = 0; i < hashData.Length; i++)
                {
                    returnValue.Append(hashData[i].ToString("x2"));
                }

                // return hexadecimal string
                return returnValue.ToString();

            }
            catch { return ""; }
        }

        /// <summary>
        /// encrypt input text using MD5 and compare it with
        /// the stored encrypted text
        /// </summary>
        /// <param name="inputData">input text you will enterd to encrypt it</param>
        /// <param name="storedHashData">the encrypted text stored on file or database ... etc</param>
        /// <returns>true or false depending on input validation</returns>
        public static bool fncValidateMD5HashData(string inputData, string storedHashData)
        {
            //hash input text and save it string variable
            string getHashInputData = fncGetMD5HashData(inputData);

            if (string.Compare(getHashInputData, storedHashData) == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// encrypt input text using SHA1 and compare it with
        /// the stored encrypted text
        /// </summary>
        /// <param name="inputData">input text you will enterd to encrypt it</param>
        /// <param name="storedHashData">the encrypted text stored on file or database ... etc</param>
        /// <returns>true or false depending on input validation</returns>
        public static bool fncValidateSHA1HashData(string inputData, string storedHashData)
        {
            //hash input text and save it string variable
            string getHashInputData = fncGetSHA1HashData(inputData);

            if (string.Compare(getHashInputData, storedHashData) == 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Tính số tháng giữa 2 khoảng thời gian
        /// </summary>
        /// <param name="dtStart"></param>
        /// <param name="dtEnd"></param>
        /// <returns></returns>
        public static int fncMonthDifference(DateTime dtStart, DateTime dtEnd)
        {
            try
            {
                return Math.Abs((dtStart.Month - dtEnd.Month) + 12 * (dtStart.Year - dtEnd.Year));
            }
            catch { return 0; }
        }


        /// <summary>
        /// Tính điểm tổng kết văn hóa
        /// </summary>
        /// <param name="fltHs11">Điểm hệ số 1</param>
        /// <param name="fltHs12"></param>
        /// <param name="fltHs13"></param>
        /// <param name="fltHs21">Điểm hệ số 2</param>
        /// <param name="fltHs22"></param>
        /// <param name="fltHs23"></param>
        /// <param name="fltHs3">Điểm hệ số 3</param>
        /// <returns></returns>
        public static float fncDiemTongKetVanHoa(float fltHs11, float fltHs12, float fltHs13
                                                , float fltHs21, float fltHs22, float fltHs23
                                                , float fltHs3)
        {
            return ((fltHs11 + fltHs12 + fltHs13) + ((fltHs21 + fltHs22 + fltHs23) * 2) + (fltHs3 * 3)) / 12;
        }


        /// <summary>
        /// Tính điểm tổng kết cả năm văn hóa
        /// </summary>
        /// <param name="fltTongKet10"></param>
        /// <param name="fltTongKet11"></param>
        /// <param name="fltTongKet12"></param>
        /// <returns></returns>
        public static float fncDiemCaNamVanHoa(float fltTongKet10, float fltTongKet11, float fltTongKet12)
        {
            return (fltTongKet10 + fltTongKet11 + fltTongKet12) / 3;
        }


        /// <summary>
        /// Tính điểm tổng kết module/môn học
        /// </summary>
        /// <param name="emTrinhDo"></param>
        /// <param name="lstDiemDinhKy"></param>
        /// <param name="fltDiemKetThucMon"></param>
        /// <returns></returns>
        public static float fncDiemTongKetMonNghe(clsEnum.TRINH_DO_DAO_TAO emTrinhDo, List<float> lstDiemDinhKy, int intSoDiemDinhKy, float fltDiemKetThucMon)
        {
            float fltKQ = 0;

            for (int i = 0; i <= intSoDiemDinhKy - 1; i++)
            {
                fltKQ += lstDiemDinhKy[i];
            }

            //if (emTrinhDo == clsEnum.TRINH_DO_DAO_TAO.SO_CAP)
            //{ 
            //    //sơ cấp nghề
            //    fltKQ = (fltKQ + (2 * fltDiemKetThucMon)) / (intSoDiemDinhKy + 2);
            //}
            //else
            //{
            //cao đẳng hoặc trung cấp nghề
            fltKQ = ((2 * fltKQ) + (3 * fltDiemKetThucMon)) / (2 * intSoDiemDinhKy + 3);
            //}

            return fltKQ;
        }

        /// <summary>
        /// Convert bitmap to byte[]
        /// </summary>
        /// <param name="img"></param>
        /// <returns></returns>
        public static byte[] fncCnvImageToByte(Image img)
        {
            if (img == null) return null;
            ImageConverter converter = new ImageConverter();
            return (byte[])converter.ConvertTo(img, typeof(byte[]));
        }


        public static string fncGetXepLoai(float fltDiemXepLoai)
        {
            string strResult = "";

            try
            {
                if (fltDiemXepLoai >= 9.0F) return "Xuất sắc";
                if (fltDiemXepLoai < 9.0F && fltDiemXepLoai >= 8.0F) return "Giỏi";
                if (fltDiemXepLoai < 8.0F && fltDiemXepLoai >= 7.0F) return "Khá";
                if (fltDiemXepLoai < 7.0F && fltDiemXepLoai >= 6.0F) return "TB Khá";
                if (fltDiemXepLoai < 6.0F && fltDiemXepLoai >= 5.0F) return "Trung bình";
            }
            catch { }

            return strResult;
        }

        //private void InstallUpdateSyncWithInfo()
        //{
        //    UpdateCheckInfo info = null;

        //    if (ApplicationDeployment.IsNetworkDeployed)
        //    {
        //        ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

        //        try
        //        {
        //            info = ad.CheckForDetailedUpdate();

        //        }
        //        catch (DeploymentDownloadException dde)
        //        {
        //            MessageBox.Show("The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + dde.Message);
        //            return;
        //        }
        //        catch (InvalidDeploymentException ide)
        //        {
        //            MessageBox.Show("Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message);
        //            return;
        //        }
        //        catch (InvalidOperationException ioe)
        //        {
        //            MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message);
        //            return;
        //        }

        //        if (info.UpdateAvailable)
        //        {
        //            Boolean doUpdate = true;

        //            if (!info.IsUpdateRequired)
        //            {
        //                DialogResult dr = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButtons.OKCancel);
        //                if (!(DialogResult.OK == dr))
        //                {
        //                    doUpdate = false;
        //                }
        //            }
        //            else
        //            {
        //                // Display a message that the app MUST reboot. Display the minimum required version.
        //                MessageBox.Show("This application has detected a mandatory update from your current " +
        //                    "version to version " + info.MinimumRequiredVersion.ToString() +
        //                    ". The application will now install the update and restart.",
        //                    "Update Available", MessageBoxButtons.OK,
        //                    MessageBoxIcon.Information);
        //            }

        //            if (doUpdate)
        //            {
        //                try
        //                {
        //                    ad.Update();
        //                    MessageBox.Show("The application has been upgraded, and will now restart.");
        //                    Application.Restart();
        //                }
        //                catch (DeploymentDownloadException dde)
        //                {
        //                    MessageBox.Show("Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + dde);
        //                    return;
        //                }
        //            }
        //        }
        //    }
        //}


        /// <summary>
        /// Kiểm tra giá trị có tồn tại trong 1 datatable
        /// </summary>
        /// <param name="tblSource">datatable source</param>
        /// <param name="strField">trường cần kiểm tra</param>
        /// <param name="strCriteria">dữ liệu so sánh</param>
        /// <returns></returns>
        public static bool fncDataExist(DataTable tblSource, string strField, string strCriteria)
        {
            bool blnResult = false;
            try
            {
                if (tblSource == null) return false;
                if (tblSource.Rows.Count <= 0) return false;

                DataRow[] objRows = tblSource.Select(string.Format("{0} Like '{1}'", strField, strCriteria));

                if (objRows.Length <= 0) return false;

                return true;
            }
            catch (Exception ex) { clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message); }
            return blnResult;
        }

        /// <summary>
        /// Xóa toàn bộ thông tin 1 hs.
        /// </summary>
        /// <param name="intHsID"></param>
        /// <returns></returns>
        public static bool fncDeleteHs(int intHsID)
        {
            try
            {
                bool blnSucess = true;

                Program.gobjTrans = Program.gobjConn.BeginTransaction();

                DAO.THocSinhAnhDAO.Delete(Program.gobjDb, Program.gobjTrans, intHsID);
                DAO.THocSinhDiemTotNghiepDAO.Delete(Program.gobjDb, Program.gobjTrans, string.Format("HS_ID = {0}", intHsID));
                DAO.THocSinhDiemTotNghiepVanHoaDAO.Delete(Program.gobjDb, Program.gobjTrans, string.Format("HS_ID = {0}", intHsID));
                DAO.THocSinhMonDAO.Delete(Program.gobjDb, Program.gobjTrans, string.Format("HS_ID = {0}", intHsID));
                DAO.THocSinhMonVanHoaDAO.Delete(Program.gobjDb, Program.gobjTrans, string.Format("HS_ID = {0}", intHsID));
                DAO.THocSinhTongKetDAO.Delete(Program.gobjDb, Program.gobjTrans, string.Format("HS_ID = {0}", intHsID));
                DAO.TLopHocSinhDAO.Delete(Program.gobjDb, Program.gobjTrans, string.Format("HS_ID = {0}", intHsID));
                DAO.TLopVanHoaHocSinhDAO.Delete(Program.gobjDb, Program.gobjTrans, string.Format("HS_ID = {0}", intHsID));
                DAO.TThiHetMonHocSinhDAO.Delete(Program.gobjDb, Program.gobjTrans, string.Format("HS_ID = {0}", intHsID));
                DAO.TThiTotNghiepHocSinhDAO.Delete(Program.gobjDb, Program.gobjTrans, string.Format("HS_ID = {0}", intHsID));
                DAO.TDanhSachDuTuyenDAO.Delete(Program.gobjDb, Program.gobjTrans, string.Format("HS_ID = {0}", intHsID));

                blnSucess = blnSucess && DAO.THocSinhDAO.Delete(Program.gobjDb, Program.gobjTrans, intHsID);

                if (blnSucess) Program.gobjTrans.Commit();
                else Program.gobjTrans.Rollback();

                return blnSucess;
            }
            catch (Exception ex)
            {
                clsCommon.fncMsgError(MethodBase.GetCurrentMethod().ReflectedType.Name, MethodBase.GetCurrentMethod().Name, ex.Message);
                return false;
            }
        }

        /// <summary>
        /// Check quyen
        /// </summary>
        /// <returns></returns>
        public static bool fncCheckRole(List<string> lstRoles, string strRoleCode, bool blnShowMessage = true)
        {
            try
            {
                //neu co cho chay tiep
                if (lstRoles.Contains(strRoleCode)) return true;

                //neu ko thi thong bao
                if (blnShowMessage) clsCommon.fncMsgError("Bạn không có quyền sử dụng chức năng này.");
                return false;
            }
            catch { return false; }
        }

    }
}